﻿using HamcoWcs.Entitys.Devices;
using HamcoWcs.Models.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace HamcoWcs.Models.Devices
{
    public class MachineStateMode
    {
        public string MachineName { get; set; }

        public double MachineDescription { get; set; }

        public DateTime StrartTime { get; set; }
        public DateTime EndTime { get; set; }

        public EnumMachineState MachineState { get; set; }

        public event EventHandler<DevicesStateSaveEvent> DevicesStateSaveEvent;
        public MachineStateMode(string machineName) 
        {
            MachineName = machineName;
            StrartTime = DateTime.Now;
        }
        public MachineStateMode()
        {
        }

       

        public void UpateData(EnumMachineState machineState)
        {
            EndTime = DateTime.Now;
            MachineDescription = (EndTime - StrartTime).TotalSeconds;
            var machineStateDto = new MachineState()
            {
                MachineName = MachineName,
                MachineDescription = MachineDescription,
                StrartTime = StrartTime,
                EndTime = EndTime,
                MachineStatus = MachineState.ToString(),
            };
            if ((int)MachineDescription != 0)
            {
                DevicesStateSaveEvent?.Invoke(this, new DevicesStateSaveEvent()
                {
                    MachineState = machineStateDto
                });
            }
            else
            {
                Console.Write($"{MachineName} {machineState}");
            }
            StrartTime = DateTime.Now;
            MachineState = machineState;
        }
    }
}
